import { Message, MessageBox } from 'element-ui'
import {
  getWindPowerList,
  addInsertEnergyStation,
  getPdf,
  downloadCommonStationWin,
  deleteEnergyStation,
} from '@/api/windPower.js'
import {
  adjustRegulationList,
  regulationOrgList,
  stationTypeList,
  voltageLevelList,
  queryStationNameList,
} from '@/api/dict.js'
import WindPowerEdit from '@/views/windPower/windPowerEdit/windPowerEdit.vue'
//引入VueOfficePdf组件
import * as XLSX from 'xlsx'
import PinyinMatch from 'pinyin-match'
import {getUrlParams} from '@/utils/params'

export default {
  components: { WindPowerEdit },
  name: 'LabProjectIndex',
  data() {
    let productionFormatter = (row) => {
      if (row.production == 1) return '是'
      if (row.production == 0) return '否'
    }
    let regulationFormatter = (row) => {
      if (row.regulation == 1) return '是'
      if (row.regulation == 0) return '否'
    }
    let responseFormatter = (row) => {
      if (row.response == 1) return '是'
      if (row.response == 0) return '否'
    }
    let yesOrNoList = {
      0: '否',
      1: '是',
    }
    let enableList = {
      0: '退出',
      1: '启用',
    }
    let isResponseList = {
      0: '暂未开展惯量响应试验',
    }
    return {
      queryStationNameList,
      getWindPowerList,
      formData: new FormData(),
      excelData: [],
      columns: [],
      pdf: '', //设置文档地址
      getFrom: {}, //每行的数据
      dispatchList: [], //调度
      stationTypeLists: [], //类型
      adjustRegulationLists: [], //上下调投入分类下拉框的数据
      voltageLevelLists: [], //电压等级下拉框的数据
      addDialogVisibleTitle: '新增',
      id: 0,
      queryDetailParam: {
        regulationOrgId: '',
        voltageLevelCode: '',
        stationName: '',
        ownersName: '',
        isProduction: null,
        capStart: '',
        capEnd: '',
        productionTime: '',
        isRegulation: null,
        adjustRegulationCode: '',
        isResponse: null,
        stationType: '7',
        powerStart: '',
        powerEnd: '',
        speedStart: '',
        speedEnd: '',
        powerDurationStart: '',
        powerDurationEnd: '',
      },
      queryParam1: { regulationOrgId: '' },
      operate: 'add',
      // 数据源
      // commonAddr: [
      //   {
      //     value: '选项1',
      //     label: '黄金糕',
      //   },
      //   {
      //     value: '选项2',
      //     label: '双皮奶',
      //   },
      //   {
      //     value: '选项3',
      //     label: '蚵仔煎',
      //   },
      //   {
      //     value: '选项4',
      //     label: '龙须面',
      //   },
      //   {
      //     value: '选项5',
      //     label: '北京烤鸭',
      //   },
      // ],

      commonAddr: [],
      copycommonAddr: [],

      // 复制一份数据
      // copycommonAddr: [
      //   {
      //     value: '选项1',
      //     label: '黄金糕',
      //   },
      //   {
      //     value: '选项2',
      //     label: '双皮奶',
      //   },
      //   {
      //     value: '选项3',
      //     label: '蚵仔煎',
      //   },
      //   {
      //     value: '选项4',
      //     label: '龙须面',
      //   },
      //   {
      //     value: '选项5',
      //     label: '北京烤鸭',
      //   },
      // ],

      isYes: [
        {
          label: '是',
          value: '1',
        },
        {
          label: '否',
          value: '0',
        },
      ],
      headList: [
        {
          name: '所属调管调度机构',
          value: 'regulationOrgName',
          noSort: true,
        },
        { name: '场站名称', value: 'stationName', noSort: true },
        { name: '升压站接入电压等级', value: 'voltageLevelName', noSort: true },
        { name: '产权单位', value: 'ownersName', noSort: true },
        {
          name: '是否已整站投产',
          value: 'isProduction',
          noSort: true,
          //formatter: (row) => (row.isProduction == 1 ? "是" : "否"),
          // formatter: productionFormatter,
          formatter: (row) =>
            yesOrNoList[row.isProduction] ? yesOrNoList[row.isProduction] : '',
        },
        {
          name: '整站容量',
          value: 'stationCap',
          noSort: true,
          formatter: (row) => (row.stationCap ? `${row.stationCap}MW` : ''),
        },
        { name: '整站投产时间', value: 'productionTime', noSort: true },
        {
          name: '是否已投入',
          value: 'isRegulation',
          noSort: true,
          // formatter: regulationFormatter,
          //formatter: (row) => (row.isRegulation == 1 ? "是" : "否"),
          formatter: (row) =>
            yesOrNoList[row.isRegulation] ? yesOrNoList[row.isRegulation] : '',
        },
        {
          name: '投入时间',
          value: 'regulationTime',
          noSort: true,
          formatter: (row) =>
            row.regulationTime ? row.regulationTime.replace('T', ' ') : '',
        },
        { name: '未按期投入原因', value: 'unRegulateReason', noSort: true },
        {
          name: '上调/下调是否投入',
          value: 'adjustRegulationName',
          noSort: true,
        },
        {
          name: '是否具备惯量响应',
          value: 'isResponse',
          noSort: true,
          formatter: (row) =>
            yesOrNoList[row.isResponse] ? yesOrNoList[row.isResponse] : '',
          // formatter: (row) => (row.isResponse == 1 ? "是" : "否"),
        },
        { name: '试验单位', value: 'testingUnitName', noSort: true },
        {
          name: '死区',
          value: 'deadZone',
          noSort: true,
          formatter: (row) => (row.deadZone ? `±${row.deadZone}Hz` : ''),
        },
        {
          name: '调差系数',
          value: 'adjustRatio',
          noSort: false,
          formatter: (row) => (row.adjustRatio ? `${row.adjustRatio}%` : ''),
        },
        {
          name: '启动功率门槛',
          value: 'startingPowerThreshold',
          noSort: true,
          formatter: (row) =>
            row.startingPowerThreshold ? `${row.startingPowerThreshold}MW` : '',
        },
        {
          name: '下调限幅',
          value: 'lowerLimit',
          noSort: true,
          formatter: (row) => (row.lowerLimit ? `${row.lowerLimit}MW` : ''),
        },
        {
          name: '上调限幅',
          value: 'upLimit',
          noSort: true,
          formatter: (row) => (row.upLimit ? `${row.upLimit}MW` : ''),
        },
        {
          name: '启动时间',
          value: 'startTime',
          noSort: true,
          formatter: (row) => (row.startTime ? `≤${row.startTime}s` : ''),
        },
        {
          name: '响应时间',
          value: 'responseTime',
          noSort: true,
          formatter: (row) => (row.responseTime ? `≤${row.responseTime}s` : ''),
        },
        {
          name: '调节时间',
          value: 'adjustTime',
          noSort: true,
          formatter: (row) => (row.adjustTime ? `≤${row.adjustTime}s` : ''),
        },
        {
          name: '最大上下调节能力',
          value: 'maxUpdownPower',
          noSort: true,
          formatter: (row) =>
            row.maxUpdownPower ? `${row.maxUpdownPower}MW` : '',
        },
        {
          name: '每分钟调节速率',
          value: 'adjustSpeed',
          noSort: true,
          formatter: (row) => (row.adjustSpeed ? `${row.adjustSpeed}MW` : ''),
        },
        {
          name: '最大调节能力持续响应时间',
          value: 'maxUpdownPowerDuration',
          noSort: true,
          formatter: (row) =>
            row.maxUpdownPowerDuration ? `${row.maxUpdownPowerDuration}s` : '',
        },
        {
          name: '功率调节偏差',
          value: 'powerAdjustDeviation',
          noSort: true,
          formatter: (row) =>
            row.powerAdjustDeviation ? `${row.powerAdjustDeviation}MW` : '',
        },
        {
          name: '一次调频投退功能',
          value: 'onOffFunction',
          noSort: true,
          formatter: (row) =>
            enableList[row.onOffFunction] ? enableList[row.onOffFunction] : '',
        },
        {
          name: '一次调频上调功能',
          value: 'isUpFunction',
          noSort: true,
          formatter: (row) =>
            enableList[row.isUpFunction] ? enableList[row.isUpFunction] : '',
        },
        {
          name: '一次调频下调功能',
          value: 'isLowerFunction',
          noSort: true,
          formatter: (row) =>
            enableList[row.isLowerFunction]
              ? enableList[row.isLowerFunction]
              : '',
        },
        {
          name: '惯量响应功能',
          value: 'isResponseFunction',
          noSort: true,
          formatter: (row) =>
            isResponseList[row.isResponseFunction]
              ? isResponseList[row.isResponseFunction]
              : '',
        },
        {
          name: '一次调频与AGC协调控制',
          value: 'agcControlName',
          noSort: true,
        },
        // {
        //   name: '一次调频实验方案',
        //   value: 'regulationTestPlan',
        //   order: 'regulationTestPlanId',
        //   noSort: true,
        //   type: 'linkPreview',
        //   clickPreview: this.doPreview,
        //   clickDownload: this.doDownload,
        // },
        // {
        //   name: '实验方案上传时间',
        //   value: 'regulationTime1',
        //   noSort: true,
        //   formatter: (row) =>
        //     row.regulationTestPlan
        //       ? row.regulationTestPlan.createTime.replace('T', ' ')
        //       : '',
        // },
        // {
        //   name: '一次调频测试报告',
        //   value: 'regulationTestReport',
        //   order: 'regulationTestReportId',
        //   noSort: true,
        //   type: 'linkPreview',
        //   clickPreview: this.doPreview,
        //   clickDownload: this.doDownload,
        // },
        // {
        //   name: '测试报告上传时间',
        //   value: 'regulationTime3',
        //   noSort: true,
        //   formatter: (row) =>
        //     row.regulationTestReport
        //       ? row.regulationTestReport.createTime.replace('T', ' ')
        //       : '',
        // },
        // {
        //   name: '一次调频定值单',
        //   value: 'regulationReportForm',
        //   order: 'regulationReportFormId',
        //   noSort: true,
        //   type: 'linkPreview',
        //   clickPreview: this.doPreview,
        //   clickDownload: this.doDownload,
        // },
        // {
        //   name: '定值单上传时间',
        //   value: 'regulationTime2',
        //   noSort: true,
        //   formatter: (row) =>
        //     row.regulationReportForm
        //       ? row.regulationReportForm.createTime.replace('T', ' ')
        //       : '',
        // },
        // {
        //   name: '是否滞后',
        //   value: 'isDelay',
        //   noSort: true,
        //   fontColor: true,
        //   formatter: (row) =>
        //     yesOrNoList[row.isDelay] ? yesOrNoList[row.isDelay] : '',
        // },
        // {
        //   name: '惯量响应方案',
        //   value: 'responsePlan',
        //   order: 'responsePlanId',
        //   noSort: true,
        //   type: 'linkPreview',
        //   clickPreview: this.doPreview,
        //   clickDownload: this.doDownload,
        // },
        // {
        //   name: '惯量响应报告',
        //   value: 'responseReport',
        //   order: 'responseReportId',
        //   noSort: true,
        //   type: 'linkPreview',
        //   clickPreview: this.doPreview,
        //   clickDownload: this.doDownload,
        // },
      ],
      // 新增弹框显示
      dialogFormVisible: false,
      formLabelWidth: '120px',
      // 预览弹框
      dialogPreVisible: false,
      isHide:true
    }
  },

  mounted() {
    // 权限区分的时候用到  有些用户只能查看 不能编辑
    // this.$nextTick(()=>{
    //   let obj = getUrlParams()
    //   if(obj){
    //     if(obj.displayMode){
    //       this.isHide=false
    //     }else{
    //       this.isHide=true
    //     }
    //   }
    // })
  },
  created() {
    this.regulationOrgList()
    this.stationTypeList()
    this.adjustRegulationList()
    this.voltageLevelList()

    this.queryParam1.regulationOrgId =  this.queryDetailParam.regulationOrgId

    // this.queryStationNameList()
  },
  methods: {
    // getUrlParams() {
    //   let url = window.location.href
    //   // 通过 ? 分割获取后面的参数字符串
    //   let urlStr = url.split('?')[1]
    //   // 创建空对象存储参数
    //   let obj = {}
    //   if (urlStr) {
    //     // 再通过 & 将每一个参数单独分割出来
    //     let paramsArr = urlStr.split('&')
    //     for (let i = 0, len = paramsArr.length; i < len; i++) {
    //       // 再通过 = 将每一个参数分割为 key:value 的形式
    //       let arr = paramsArr[i].split('=')
    //       obj[arr[0]] = arr[1]
    //     }
    //     // return obj
    //     if (obj) {
    //       if (obj.displayMode) {
    //         this.modeDisplay = false
    //       } else {
    //         this.modeDisplay = true
    //       }
    //     }
    //   }
    // },
    inputChange(val) {
      console.log(val, '搜索下拉框val')
      this.queryDetailParam.stationName = this.$refs.stationRef.value
    },

    regulationOrgChange(val){
      this.queryParam1.regulationOrgId = val
      this.$refs.stationRef.getDataInit()
    },

    handleClear_1() {
      this.$set(this.queryDetailParam, 'stationName', '')
    },

    renderedHandler() {
      console.log('渲染完成')
    },
    errorHandler() {
      console.log('渲染失败')
    },

    // 总调下拉框的数据
    async regulationOrgList() {
      await regulationOrgList().then((res) => {
        if (res.code === '000000') {
          this.dispatchList = res.data
        }
      })
    },

    // 上下调投入分类下拉框的数据
    async adjustRegulationList() {
      await adjustRegulationList().then((res) => {
        if (res.code === '000000') {
          this.adjustRegulationLists = res.data
        }
      })
    },
    // 场站类型下拉框的数据
    async stationTypeList() {
      await stationTypeList().then((res) => {
        if (res.code === '000000') {
          this.stationTypeLists = res.data
        }
      })
    },
    // 电压等级下拉框的数据
    async voltageLevelList() {
      await voltageLevelList().then((res) => {
        if (res.code === '000000') {
          this.voltageLevelLists = res.data
        }
      })
    },
    // 新增弹框
    addWindPower() {
      this.id++
      this.operate === 'add'
      this.dialogFormVisible = true
      this.addDialogVisibleTitle = '新增'
      this.getFrom = { regulationOrgId: '1' }
    },

    // 获取表格多行选中的数据
    getMultipleSelection() {
      this.tableData = JSON.parse(
        JSON.stringify(this.$refs.windPowerTable.multipleSelection)
      )
      this.tableData.forEach((element) => {
        this.getFrom = element
      })
    },
    // 编辑
    editWindPower() {
      this.operate = 'edit'
      this.getMultipleSelection()
      if (this.tableData && this.tableData.length < 1) {
        Message.warning('请先勾选要编辑的数据')
      } else if (this.tableData && this.tableData.length > 1) {
        Message.warning('编辑的时候只能选择一条数据,请重新选择')
        return false
      } else {
        this.addDialogVisibleTitle = '编辑'
        this.dialogFormVisible = true
        // this.$nextTick(()=>{
        // this.$refs.childRules.$refs.stationRefEdit.value=this.getFrom.stationName
        // })
        return true
      }
    },

    // 复制
    copyWindPower() {
      this.operate = 'copy'
      this.getMultipleSelection()
      if (this.tableData && this.tableData.length < 1) {
        Message.warning('请先勾选要复制的数据')
      } else if (this.tableData && this.tableData.length > 1) {
        Message.warning('复制的时候只能选择一条数据,请重新选择')
        return false
      } else {
        this.addDialogVisibleTitle = '复制'
        // 复制的时候清空所有的文件上传
        this.getFrom.regulationReportForm = ''
        this.getFrom.regulationTestPlan = ''
        this.getFrom.regulationTestReport = ''
        this.getFrom.responsePlan = ''
        this.getFrom.responseReport = ''
        this.dialogFormVisible = true
        return true
      }
    },

    // 删除
    deleteWindPower() {
      if (this.$refs.windPowerTable.multipleSelection.length === 0) {
        Message.warning('请选择要删除的数据')
        return
      }
      // 确认删除嘛
      this.$confirm('是否确认删除？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        // 发送请求
        let params = this.$refs.windPowerTable.multipleSelection.map(
          (item) => item.stationId
        )
        // 发送请求
        deleteEnergyStation(params).then((res) => {
          if (res.code === '000000') {
            Message.success('删除成功')
            this.$refs.windPowerTable.getDataInit()
          }
        })
      })
    },

    // 检索
    searchList() {
      this.$refs.windPowerTable.getDataInit()
      //console.log(this.$refs.stationRef.value,'99999')
    },
    // 重置
    resetSearchList() {
      for (let key in this.queryDetailParam) {
        this.queryDetailParam[key] = ''
      }
      this.queryDetailParam.stationType = '7'
      this.$refs.windPowerTable.getDataInit()
    },

    // 详情重置
    resetCon() {
      this.getFrom = {}
      if (this.$refs.childRules.$refs.owner) {
        this.$refs.childRules.$refs.owner.labels = ''
      }
      if (this.$refs.childRules.$refs.testingUnit) {
        this.$refs.childRules.$refs.testingUnit.labels = ''
      }
    },

    // 下载
    async doDownload(row, col, name) {
      let excelName = `${name}`
      const res = await getPdf(row[`${col}Id`])
      if (
        res.fileType !== 'pdf' &&
        res.fileType !== 'xlsx' &&
        res.fileType !== 'xls'
      ) {
        this.$message.warning('只支持pdf与excel格式的文件下载')
        return
      }
      let typeList = {
        pdf: 'application/pdf',
        xls: 'application/vnd.ms-excel',
        xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
      }
      const link = document.createElement('a')
      let blob = new Blob([res], {
        type: typeList[res.fileType],
      })
      // xlsx的文件type

      link.style.display = 'none'
      link.href = URL.createObjectURL(blob)
      link.download = excelName //下载的文件名
      document.body.appendChild(link)
      link.click()
      document.body.removeChild(link)
    },

    async downloadWin() {
      let excelName = '频率响应台账列表.xlsx'
      const res = await downloadCommonStationWin(this.queryDetailParam)
      const link = document.createElement('a')
      let blob = new Blob([res], {
        type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
      })
      link.style.display = 'none'
      link.href = URL.createObjectURL(blob)
      link.download = excelName //下载的文件名
      document.body.appendChild(link)
      link.click()
      document.body.removeChild(link)
    },

    //  导出
    exportExcel() {
      this.downloadWin()
    },

    // 预览
    async doPreview(row, col) {
      const res = await getPdf(row[`${col}Id`])
      if (
        res.fileType !== 'pdf' &&
        res.fileType !== 'xlsx' &&
        res.fileType !== 'xls'
      ) {
        this.$message.warning('只支持pdf与excel格式的文件预览')
        return
      }
      let typeList = {
        pdf: 'application/pdf',
        xls: 'application/vnd.ms-excel',
        xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
      }
      const blob = new Blob([res], { type: typeList[res.fileType] })
      if (res.fileType === 'pdf') {
        this.pdf = URL.createObjectURL(blob)
      } else {
        const reader = new FileReader()
        reader.onload = (e) => {
          const data = new Uint8Array(e.target.result)
          let workbook = XLSX.read(data, { type: 'array' }) // 解析数据
          this.tableToHtml(workbook)
        }
        reader.readAsArrayBuffer(blob)
      }
      this.dialogPreVisible = true
    },
    tableToHtml(workbook) {
      var worksheet = workbook.Sheets[workbook.SheetNames[0]]
      // var innerHTML = XLSX.utils.sheet_to_html(worksheet);
      if (document.querySelector('#tableHtml')) {
        document.querySelector('#tableHtml').innerHTML =
          XLSX.utils.sheet_to_html(worksheet)
        document.querySelector('.table-html-wrap table')
        let trs = document.querySelectorAll('tr')
        trs.forEach((tr) => {
          if (!tr.innerText.trim()) {
            tr.remove()
          }
        })
        document.querySelector('.el-dialog__body').style.overflowX = 'auto'
      }
      let tds = document.querySelectorAll('td')
    },
    // 保存
    saveForm() {
      // 校验
      let flag = this.$refs['childRules'].validateForm()
      if (flag) {
        this.addInsertEnergyStation()
        // this.dialogFormVisible = false
      } else {
        return
      }
    },

    // 首先封装参数（对象）转换为formData格式
    // getFormData(object) {
    //   const formData = new FormData();
    //   Object.keys(object).forEach((key) => {
    //     const value = object[key];
    //     if (Array.isArray(value)) {
    //       value.forEach((subValue, i) => {
    //         formData.append(key + `[${i}]`, subValue);
    //       });
    //     } else {
    //       formData.append(key, object[key]);
    //     }
    //   });
    //   return formData;
    // },

    // 首先封装参数（对象）转换为formData格式
    getFormData() {
      let form = this.$refs.childRules
      // 文件存在就append,不存在就不append,不往后台传递这个字段
      form.fileList1[0] &&
        this.formData.set('regulationReportForm', form.fileList1[0].raw)
      form.fileList2[0] &&
        this.formData.set('regulationTestPlan', form.fileList2[0].raw)
      form.fileList3[0] &&
        this.formData.set('regulationTestReport', form.fileList3[0].raw)
      form.fileList4[0] &&
        this.formData.set('responsePlan', form.fileList4[0].raw)
      form.fileList5[0] &&
        this.formData.set('responseReport', form.fileList5[0].raw)
      this.formData.set(
        'regulationOrgId',
        this.getFrom.regulationOrgId ? this.getFrom.regulationOrgId : null
      )
      // this.formData.set(
      //   'stationName',
      //   this.$refs.childRules.$refs.stationRefEdit.value? this.$refs.childRules.$refs.stationRefEdit.value : null
      // )
      this.formData.set(
        'stationName',
        this.getFrom.stationName ? this.getFrom.stationName : null
      )
      this.formData.set(
        'voltageLevelCode',
        this.getFrom.voltageLevelCode ? this.getFrom.voltageLevelCode : ''
      )
      this.formData.set('ownersName', this.getFrom.ownersName)
      this.formData.set('isProduction', this.getFrom.isProduction)
      this.formData.set('stationCap', this.getFrom.stationCap)
      this.formData.set('isRegulation', this.getFrom.isRegulation)
      this.formData.set('productionTime', this.getFrom.productionTime)
      if (
        this.getFrom.regulationTime === undefined ||
        this.getFrom.regulationTime === null
      ) {
        delete this.getFrom.regulationTime
      } else {
        this.formData.set('regulationTime', this.getFrom.regulationTime)
      }
      //this.getFrom.regulationTime && this.formData.set('regulationTime', this.getFrom.regulationTime.replace('T', ' '))
      this.formData.set('unRegulateReason', this.getFrom.unRegulateReason)
      // 上调/下调是否投入
      this.formData.set(
        'adjustRegulationCode',
        this.getFrom.adjustRegulationCode
      )
      if (
        this.getFrom.isResponse === undefined ||
        this.getFrom.isResponse === null
      ) {
        delete this.getFrom.isResponse
      } else {
        this.formData.set('isResponse', this.getFrom.isResponse)
      }

      this.getFrom.deadZone &&
        this.formData.set('deadZone', this.getFrom.deadZone)
      this.getFrom.adjustRatio &&
        this.formData.set('adjustRatio', this.getFrom.adjustRatio)
      this.getFrom.startingPowerThreshold &&
        this.formData.set(
          'startingPowerThreshold',
          this.getFrom.startingPowerThreshold
        )
      this.getFrom.lowerLimit &&
        this.formData.set('lowerLimit', this.getFrom.lowerLimit)
      this.getFrom.powerAdjustDeviation &&
        this.formData.set(
          'powerAdjustDeviation',
          this.getFrom.powerAdjustDeviation
        )
      this.getFrom.upLimit && this.formData.set('upLimit', this.getFrom.upLimit)
      this.getFrom.startTime &&
        this.formData.set('startTime', this.getFrom.startTime)
      this.getFrom.responseTime &&
        this.formData.set('responseTime', this.getFrom.responseTime)
      this.getFrom.adjustTime &&
        this.formData.set('adjustTime', this.getFrom.adjustTime)
      // 一次调频投退功能
      this.getFrom.onOffFunction &&
        this.formData.set('onOffFunction', this.getFrom.onOffFunction)
      this.getFrom.isUpFunction &&
        this.formData.set('isUpFunction', this.getFrom.isUpFunction)
      this.getFrom.isLowerFunction &&
        this.formData.set('isLowerFunction', this.getFrom.isLowerFunction)
      this.getFrom.isResponseFunction &&
        this.formData.set('isResponseFunction', this.getFrom.isResponseFunction)
      this.getFrom.agcControl &&
        this.formData.set('agcControl', this.getFrom.agcControl)
      this.getFrom.maxUpdownPower &&
        this.formData.set('maxUpdownPower', this.getFrom.maxUpdownPower)
      this.getFrom.adjustSpeed &&
        this.formData.set('adjustSpeed', this.getFrom.adjustSpeed)
      this.getFrom.maxUpdownPowerDuration &&
        this.formData.set(
          'maxUpdownPowerDuration',
          this.getFrom.maxUpdownPowerDuration
        )

      // 区分新增或者删除的时候传参
      if (this.operate === 'add' || this.operate === 'copy') {
        this.formData.set('operateCode', '1')
        this.formData.set('stationType', '7')
      }

      if (this.operate === 'edit') {
        this.formData.set('operateCode', '2')
        this.formData.set(
          'stationId',
          this.$refs.windPowerTable.multipleSelection[0].stationId
        )
        this.formData.set(
          'regulationId',
          this.$refs.windPowerTable.multipleSelection[0].regulationId
        )
        this.formData.set('stationType', '7')
      }

      return this.formData
    },

    async addInsertEnergyStation() {
      this.formData = this.getFormData()
      this.formData.set('ownersId', this.$refs.childRules.$refs.owner.labels)
      this.formData.set(
        'testingUnitId',
        this.$refs.childRules.$refs.testingUnit.labels
      )
      await addInsertEnergyStation(this.getFormData(this.formData)).then(
        (res) => {
          if (res.code === '000000') {
            Message.success(`${this.addDialogVisibleTitle}成功`)
            this.$refs.windPowerTable.getDataInit()
            this.dialogFormVisible = false
          }
          if (res.code === '400001') {
            this.$message.error(res.mesg)
            this.dialogFormVisible = true
            // this.$confirm(res.mesg, '提示', {
            //   confirmButtonText: '确定',
            //   cancelButtonText: '取消',
            //   type: 'warning',
            // }).then(()=>{
            //   this.dialogFormVisible = true
            // })
          }
        }
      )
      // .catch((err) => {
      //   Message.error(`${this.addDialogVisibleTitle}失败`);
      // });
    },

    remoteMethod(query) {
      if (query !== '') {
        this.loading = true
        setTimeout(() => {
          this.loading = false
          this.options = this.list.filter((item) => {
            return item.label.toLowerCase().indexOf(query.toLowerCase()) > -1
          })
        }, 200)
      } else {
        this.options = []
      }
    },
    // 过滤方法, 接收一个输入框内容作为参数, 当输入框内容改变后会执行
    PinyinMatchFun(val) {
      if (val) {
        // 定义一个空数组用来存储过滤后的数据
        var result = [] // 开始循环过滤内容
        this.copycommonAddr.forEach((i) => {
          // 调用 PinyinMatch.match 方法进行拼音与汉字匹配
          var m = PinyinMatch.match(i.label, val)
          if (m) {
            // 匹配成功则push到result数组中
            result.push(i)
          }
        }) // 将过滤后的数组重新赋给下拉列表数据
        this.commonAddr = result
      } else {
        // 如果输入框为空, 则将下拉列表数据还原
        this.commonAddr = this.copycommonAddr
      }
    },

    // 电厂名称下拉框的数据
    //  async queryStationNameList() {
    //   await queryStationNameList().then((res) => {
    //     if (res.code === '000000') {
    //       this.commonAddr = res.data
    //       this.copycommonAddr = res.data
    //     }
    //   })
    // },
  },
}
